<?php
/**
 * 转码服务入口文件
 */
ini_set('date.timezone', 'Asia/Shanghai');
ini_set('display_errors', 'On');

define('INTERFACE_PATH', dirname(__FILE__) . "/interface");
error_reporting(E_ALL ^ E_NOTICE);
error_reporting(E_ALL ^ E_WARNING);
define('UPLOAD_BOOT', dirname(__FILE__) . '/');
defined("WEB_LOG_PATH") OR define("WEB_LOG_PATH", "./logs/");
defined("LOG_SWITCH") OR define("LOG_SWITCH", TRUE);

require 'interface/functions.php';
spl_autoload_register('archive_loader');
register_shutdown_function('mg_shunt_down');

try {
    Mg()->response = new MgResponse();
    Mg()->config = (require INTERFACE_PATH . '/config/common.conf.php');
    Mg()->log = Log::get_instance();
    Mg()->mongo = BaseMongo::get_mongoInstance();

    $path = getgpc('route'); // 获取路由
    if (empty($path)) {
        $path = 'video';
    }

    // 解析路由
    $route = parse_path($path);
    $controller = isset($route[0]) ? $route[0] : 'index';
    $method = isset($route[1]) ? $route[1] : 'index';
    $app = new $controller();
    $app->init($method);
} catch(MgException $e){
    Mg()->response->status = (null !== $e->getCode()) ? $e->getCode() : -1;
    Mg()->response->msg = $e->getMessage();
} catch(\Exception $e){
    Mg()->response->status = (null !== $e->getCode()) ? $e->getCode() : -2;
    Mg()->response->msg = iconv('', 'utf-8', $e->getMessage());
}
Mg()->response->response();
